package com.mischa.atc.tests.clearances;

import junit.framework.Assert;

import org.junit.Test;

import com.mischa.atc.Aircraft;
import com.mischa.atc.Clearance;
import com.mischa.atc.Flight;
import com.mischa.atc.clearances.HeadingClearance;

public class HeadingClearanceTest 
{
	@Test
	public void HeadingClearanceSetsTargetHeadingAndIsImmediatelyCompleted()
	{			
		Aircraft aircraft = new Aircraft();
		aircraft.setSpeed(250);
		
		Flight flight = new Flight(aircraft);
	
		Clearance clearance = new HeadingClearance(90);
		flight.clear(clearance, true);
		
		Assert.assertEquals(360f, flight.getHeading().get());
		Assert.assertFalse(clearance.isComplete());
		
		flight.update(1);
		
		Assert.assertEquals(90f, flight.getClearedHeading().get());
		// Aircraft started turning, but is not yet heading in final direction	
		Assert.assertTrue(aircraft.getHeading().liesBetweenCW(360, 90));
		Assert.assertFalse(90f == aircraft.getHeading().get());
		Assert.assertTrue(clearance.isComplete());
		
		flight.update(60);
		
		Assert.assertEquals(90f, aircraft.getHeading().get());
	}
}
